<template>
  <div class="app-container home">
    <div class="analysis box">
      <div class="title">数据统计</div>
      <div ref="chartRef" class="chart-wrapper">
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import store from "../store";
import router from "../router";
export default {
  name: 'Index',
  data() {
    return {
      lineChartData: {
        expectedData: [100, 120, 161, 134, 105, 160, 165],
        actualData: [120, 82, 91, 154, 162, 140, 145],
        dates: ['2023-03-15', '2023-03-16', '2023-03-17', '2023-03-18', '2023-03-19', '2023-03-20', '2023-03-21']
      },
    };
  },
  mounted () {
    this.drawChart()
  },
  methods: {
    /**
     * 跳转链接
     */
    goTarget(href) {
      window.open(href, '_blank');
    },
    /**
     * 绘图
     */
    drawChart () {
      this.chart = echarts.init(this.$refs.chartRef, 'macarons')
      this.setOptions(this.lineChartData)
    },
    setOptions({ expectedData, actualData, dates } = {}) {
      this.chart.setOption({
        xAxis: {
          // data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
          data: dates,
          boundaryGap: false,
          axisTick: {
            show: false
          }
        },
        grid: {
          left: 10,
          right: 40,
          bottom: 20,
          top: 30,
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          },
          padding: [5, 10]
        },
        yAxis: {
          axisTick: {
            show: false
          }
        },
        legend: {
          data: ['今日数据', '本周数据']
        },
        series: [{
          name: '今日受理数', itemStyle: {
            normal: {
              color: '#FF005A',
              lineStyle: {
                color: '#FF005A',
                width: 2
              }
            }
          },
          smooth: true,
          type: 'line',
          data: expectedData,
          animationDuration: 2800,
          animationEasing: 'cubicInOut'
        },
          {
            name: '服务数量',
            smooth: true,
            type: 'line',
            itemStyle: {
              normal: {
                color: '#3888fa',
                lineStyle: {
                  color: '#3888fa',
                  width: 2
                },
                areaStyle: {
                  color: '#f3f8ff'
                }
              }
            },
            data: actualData,
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }]
      })
    }
  },
  components: {
    // LineChart
  }
};
</script>

<style scoped lang="scss">
.home {
  display: flex;
  background: #F1F2F6;
  //min-height: calc(100vh - 84px);
  .box {
    padding: 20px;
    background: #fff;
    border-radius: 8px;
    .title {
      font-weight: bold;
    }
  }
  .analysis {
    flex: 1;
    //margin-bottom: 20px;
    //min-width: 291px;
    .chart-wrapper {
      height: 400px;
      margin-top: 30px;
    }
  }
  .shortcuts {
    width: 320px;
    margin-left: 20px;
    ul {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      list-style: none;
      padding: 0;
      li {
        margin-top: 30px;
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 50%;
        div {
          margin-top: 10px;
        }
        &:hover {
          color: #469EF7;
        }
      }
    }
  }
}
</style>

